import { http } from '@/utils/http'
import type { FormQueryData, QueryParams, UpdatePasswordData, RoleIdsData } from './types'

const PATH = '/user'

const UserAPI = {
  /** 获取列表 */
  getList(params: QueryParams) {
    return http.request<ResponseList>('get', `${PATH}`, { params })
  },
  /** 创建 */
  create(data: FormQueryData) {
    return http.request<ResponseData>('post', `${PATH}`, { data })
  },
  /** 修改 */
  update(id: number, data: FormQueryData) {
    return http.request<ResponseData>('put', `${PATH}/${id}`, { data })
  },
  /** 单选删除 */
  delete(id: number) {
    return http.request<ResponseData>('delete', `${PATH}/${id}`)
  },
  /** 多选删除 */
  batchDelete(ids: number[]) {
    return http.request<ResponseData>('delete', `${PATH}`, { data: { ids } })
  },
  updatePassword(data: UpdatePasswordData) {
    return http.request<ResponseData>('post', `${PATH}/updatePassword`, { data })
  },
  setRoleIds(data: RoleIdsData) {
    return http.request<ResponseData>('post', '/set-role-ids', { data })
  },
  getRoleIds(id: number) {
    return http.request<ResponseData>('get', `/list-role-ids/${id}`)
  }
}

export default UserAPI
